<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>我的收藏</title>
<link rel="stylesheet" href="/style/new/css/base.css">
<link rel="stylesheet" href="/style/new/css/swiper.min.css"/>
<link rel="stylesheet" href="/style/new/css/xshop.css?ver=20190416" />
<link rel="stylesheet" href="/style/new/mui/css/mui.min.css" />
<script src="/style/new/js/swiper.min.js"></script>
<script src="/style/new/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/new/js/xShop.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
</head>
<body style="background: #fff">    	
<!--top-->	
<div class="xihuan-bot footprint">
	<ul id="content">
		<?php 
		if($this->data['data']){
			foreach ($this->data['data'] as $r) {
		?>
		<li class="xihuan-bot-each" id="collectionItem<?=$r['id'];?>">
			<a href="/index/goodsdetail?goods_id=<?=$r['goods_id'] ?>">
				<div class="xihuan-bot-each-pic">
				<!-- <?php

	              if($r['market_price'] > $r['shop_price'])
	              {
	                $zhekou = number_format($r['shop_price'] / $r['market_price'],2,".","");
	                echo '<div class="zhekou">'.($zhekou * 10).'折</div>';
	                echo '<div class="sheng">省'.number_format($r['market_price'] - $r['shop_price'],2,".","").'</div>';
	              }
                
	              if($r['goods_number']==0)
	              {
	                echo '<div class="saleout">补货中</div>';
	              }
	              ?> -->
	             
				<?php if ($r['thumb_pic']!=""){ ?>
					<img src="<?=$r['thumb_pic']?>" />
				<?php }else{?>
					<img src="/style/new/images/home/xihuan-pic1.png" />
				<?php } ?>
				</div>
				<h2 class="xihuan-bot-each-title"><?= $r['goods_name']; ?></h2>
				<div class="xihuan-bot-each-fonu">
				</div>
				<!-- <div class="xihuan-bot-each-fonu">
	              <p class="xihuan-bot-each-number">已销<?=$r['sales_count']; ?>笔</p>
	              <p class="xihuan-bot-each-kucun">库存<?=$r['goods_number']; ?>件</p>
	            </div> -->
				<div class="xihuan-bot-each-money">
                    <p class="xihuan-bot-each-money-left"><b>￥<?= $r['shop_price']; ?></b><?php
                    if($r['market_price']>0)
                    {

                        echo '<del>'.$r['market_price'].'</del>';
                    }
                    ?></p>
					 <div class="remove r-del" data-collection="<?=$r['id'];?>" onclick="return false;" style="   "></div>
				</div>
			</a>
		</li>
		<?php 
			}
		}
		?>  
	</ul>
</div>

<script type="text/javascript">
var _page = <?=$this->data['page'] > 0 ? $this->data['page'] : 1;?>,
    _maxpage = <?=$this->data['maxpage'] > 0 ? $this->data['maxpage'] : 1;?>,
    _loading = false;

function isIphoneX() {
    return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375)
}
$(document).ready(function(e) {
    // 判断iPhoneX
    if (isIphoneX()) {
        $(".xihuan-bot").addClass("iPhoneX");
    }
    $(document).on("scroll", function() {
        if ($(document).scrollTop() + $(window).height() + 200 >= $(document).height() && !_loading) {
            _loading = true;
            _loadMore(_page + 1);
        }
    });
    $(".r-del").bind("click",function(){
    	_removeCollection( $(this).attr("data-collection") );
    });
});

function _loadMore(page) {
    if (page <= _maxpage && _loading) {
        _page = page;
        $.post("/user/ajax", {
            "act": "getcollection",
            "page": page,
            "mr": Math.random()
        }, function(json) {
            _loading = false;
            console.log(json);
            if (json.page == page && typeof json.data != "undefined" && json.data != null) {
                $.each(json.data, function(i, v) {
                    var _dpic = '/style/new/images/home/xihuan-pic1.png',
                        _del = '';
                    if (typeof v.thumb_pic != "undefined" && v.thumb_pic != null) {
                        _dpic = v.thumb_pic;
                    }
                    if (v.market_price > 0) {
                        _del = '<del>' + v.market_price + '</devl>';
                    }
                    var _saleout = _market_price = _zhekou = _sheng = '';
                    var _new_market_price = parseFloat(v.market_price),
                        _new_shop_price = parseFloat(v.shop_price);
                    if (v.goods_number == 0) {
                        _saleout = '<div class="saleout">补货中</div>';
                    }
                    if (_new_market_price > 0) {
                        _market_price = '<del>' + _new_market_price.toFixed(2) + '</del>';
                        if (_new_market_price > _new_shop_price) {
                            var _sm = _new_market_price - _new_shop_price;
                            var _zk = parseFloat(_new_shop_price / _new_market_price) * 10;
                            _zhekou = '<div class="zhekou">' + _zk.toFixed(1) + '折</div>';
                            _sheng = '<div class="sheng">省' + _sm.toFixed(2) + '</div>';
                        }
                    }
                    var _html = '<li class="xihuan-bot-each" id="collectionItem'+v.id+'"><a href="/index/goodsdetail?goods_id=' + v.goods_id + '"><div class="xihuan-bot-each-pic">' + _zhekou + _sheng + _saleout + '<div class="remove" data-collection="'+v.id+'" onclick="return false;"></div><img src="' + _dpic + '" /></div><h2 class="xihuan-bot-each-title">' + v.goods_name + '</h2><div class="xihuan-bot-each-fonu"></div><div class="xihuan-bot-each-fonu">                 <p class="xihuan-bot-each-number">已销' + v.sales_count + '笔</p>                  <p class="xihuan-bot-each-kucun">库存' + v.goods_number + '件</p>                </div><div class="xihuan-bot-each-money"><p class="xihuan-bot-each-money-left"><b>' + v.shop_price + '</b></p>' + _del + '</div></a></li>';
                    $("#content").append(_html);
                });

                $(".r-del").unbind("click").bind("click",function(){
			    	_removeCollection( $(this).attr("data-collection") );
			    });
            }
        }, "json");
    }
}
function _removeCollection(id)
{
	swal({
        title: "确定移除此收藏吗?",
        type: "warning",
        timer: 10000,
        cancelButtonText: "取消",
        showCancelButton: true,
        closeOnConfirm: false,
        closeOnCancel: true
    }, function(isConfirm) {
        if (isConfirm) {
            $.post("/user/ajax",
            {
                "act":"removecollection",
                "id":id,
                "mr":Math.random()
            },function(json){
                console.log(json);
                if(json.code==200)
                {
                	swal("移除成功！",false,"success");
                	$("#collectionItem"+id).remove();
                }
                else
                {
                	swal("移除失败");
                }
            },"json");
        }
    });
}
</script>
</body>
</html>